<template>
	<div style="display: inline-block" class="age-input">
		<el-input
				v-model="age"
				:readonly="true"
		></el-input>
		<span v-if="message">{{ message }}</span>
	</div>
</template>
<script>
	import Vue from 'vue';
	import ElementUI from 'element-ui';
	import Service from 'winged/utils/wt-model-service';
	import FormUtils from 'winged/utils/wt-form-utils';
	import ModelUtils from 'winged/utils/wt-model-utils';
	import moment from 'moment';
	Vue.use(ElementUI);
	export default {
		name: 'wt-case-admission-date',
		props: {
			// 字段对象（包含字段配置信息）
			field: {
				type: Object,
				required: true,
			},
			// 表单数据对象
			form: {
				type: Object,
				required: true,
			},
			paramsData: {
				type: Object,
				default: null
			},
			
		},
		computed: {
			icon() {
				return this.loading ? 'loading' : 'date';
			}
		},
		data() {
			return {
				age: this.form.patientAge,
				message: null,
				loading: false
			}
		},
		watch:{
			'form'(val){
				this.load();
				this.form.patientAge = this.age;
			}
		},
		methods:{
			reset(){
				this.load();
				this.form.patientAge = this.age;
			},
			load() {
				let current = moment(this.form.admissionDate);
				let birth = moment(this.paramsData.patientBirthday);
				this.age = current.diff(birth,'years');
			},
		},
	}
</script>
<style>
	.age-input input:read-only
	{
		background-color: #eef1f6!important;
	}
</style>